home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16698 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: mail2news.demon.co.uk!tsys.demon.co.uk
  2. From: Tom Wheeley <tomw@tsys.demon.co.uk>
  3. Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.edu
  4. Subject: Re: ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada)
  5. Date: Thu, 11 Apr 96 03:50:58 GMT
  6. Organization: City Zen FM
  7. Message-ID: <829194658snz@tsys.demon.co.uk>
  8. References: <JSA.96Feb16135027@organon.com> <dewar.828936837@schonberg> <828964950snz@genesis.demon.co.uk> <dewar.828987544@schonberg> <4kbuebINNrho@keats.ugrad.cs.ubc.ca> <dewar.829048603@schonberg> <4kets3$ic0@news-s01.ny.us.ibm.net>
  9. Reply-To: tomw@tsys.demon.co.uk
  10. X-NNTP-Posting-Host: tsys.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.30
  12. X-Sig-By: Tomsystems Quote v1.2.  (c)1996 Tom Wheeley, tomw@tsys.demon.co.uk
  13. X-Mail2News-Path: tsys.demon.co.uk
  14.  
  15. In article <4kets3$ic0@news-s01.ny.us.ibm.net>
  16.            mshan@ibm.net "Mike Shannon" writes:
  17.  
  18. > In <dewar.829048603@schonberg>, dewar@cs.nyu.edu (Robert Dewar) writes:
  19. > >There are two possible semantics that ould
  20. > >be defined for read (buffer must be at least size of the read argument,
  21. > >or buffer must be at least size of data read). Both are easy to specify,
  22. > >both are easy to implement. You cannot rely on common sense
  23. > > ...
  24. > I'm a latecomer to this dispute, but this is not smart:
  25. >     char buf[100];
  26. >     read(fd,buf,1000);
  27. > Common sense, which tells me not to do such things, is a welcome ally.
  28.  
  29. Certainly, but if I have been following this correctly, the 1000 is a red
  30. herring which casts doubt on the programmers ability.  f.e., what if some
  31. rogue process (or kernel!) manages to increase that files size to 680 bytes?
  32.  
  33. The last argument to read is your friend. :-)  If you know your file will be
  34. always 68 bytes, then put 68 there.  Even better, as I assume you are putting
  35. in the 1000 as a catchall for expansion, put a #define in, and base the size
  36. of your buffer, and the last argument to read on that. Simple and effective.
  37.  
  38. What Robert is complaining about is that he is reading a 68 byte file by
  39. requesting 1000 bytes; and that in his opinion, read should stop reading
  40. at the end of the file, and return control.
  41.  
  42. Myself, I would see this auto-stop idea as a _feature_ of read().  features
  43. can only be relied upon portably if they are positively documented in POSIX.
  44. This feature is not therefore portable, as POSIX is muddy on the matter.
  45.  
  46. I suppose in c.l.c speak, it would be called `implementation-defined'.
  47.  
  48. .splitbung
  49. -- 
  50. * TQ 1.0 * The 'Just So Quotes'.
  51. If you keep saying things are going to be bad, you have a chance of being a 
  52. prophet.
  53.     -- Isaac Bashevis Singer
  54.